<template>
  <el-dialog
    v-model="dialogVisible"
    title="删除模具仓库"
    width="900px"
    @close="closeDialog"
  >
    <div style="font-size: 18px; font-weight: 600; color: black">
      确定删除模具仓库&nbsp;&nbsp;&nbsp;{{ state.form.whName }}&nbsp;?
    </div>

    <template #footer>
      <span class="dialog-footer">
        <el-button @click="closeDialog">取消</el-button>
        <el-button type="primary" @click="deleteWh">删除</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup>
  import { deleteMoldWhApi } from '@/api/equip/mold_api'

  const $baseLoading = inject('$baseLoading')
  const $baseMessage = inject('$baseMessage')

  const dialogVisible = ref(false)

  const state = reactive({
    form: {},
  })

  const closeDialog = () => {
    dialogVisible.value = false
  }

  const openDialog = (value) => {
    state.form = value
    dialogVisible.value = true
  }

  const deleteWh = async () => {
    const load = $baseLoading()
    try {
      let params = {
        pkMoldWh: state.form.pkMoldWh,
      }
      const { code, msg } = await deleteMoldWhApi(params)
      if (code === 2000) {
        $baseMessage(msg, 'success')
        dialogVisible.value = false
        _emit('success-callback')
      } else {
        $baseMessage(msg, 'error')
      }
    } finally {
      load.close()
    }
  }

  defineExpose({ openDialog })
  const _emit = defineEmits(['success-callback'])
</script>
